import Taro, { Component } from '@tarojs/taro'
import { View } from '@tarojs/components'
import { DNavBar, DAtInpute } from '@/components'
import http from '@/api'
import { AtForm, AtTextarea, AtButton } from 'taro-ui'
import './mycompanyintro.scss'

export default class EditnameBox extends Component {

    constructor(props) {
        super(props)
        this.state = {
            newName: ""
        }
    }
    componentDidMount() {
        let { synopsis } = this.$router.params

        let intro = sessionStorage.getItem('companyintro')
        this.setState({
            newName: JSON.parse(intro)
        })
        if (synopsis) {
            this.setState({
                newName: synopsis
            })
        }
    }
    onChangeName(e) {
        this.setState({
            newName: e
        })
    }

    onSubmit() {
        let { newName } = this.state
        if (!newName) {
            return Taro.showToast({
                title: "请输入内容",
                icon: 'none'
            })
        }
        http.editEntryPriseintro({ entInfo: newName }).then(res => {
            if (!res) {
                return
            }
            Taro.showToast({
                title: "已修改",
                duration: 800
            }).then(() => {
                setTimeout(() => {
                    Taro.navigateBack({ delta: 1 })
                }, 1000)
            })
        })
    }

    render() {
        const {
            newName
        } = this.state
        return (
            <View className='b_mycompanyintro'>
                <DNavBar title='编辑企业简介'></DNavBar>
                <View className='b_mycompanyintro__box'>
                    <View className='b_mycompanyintro__form '>
                        <AtForm>
                            <AtTextarea
                                count={true}
                                autoFocus={true}
                                value={newName}
                                onChange={this.onChangeName.bind(this)}
                                maxLength={100}
                                height={200}
                                placeholder='请输入您的企业简介...'
                            />
                        </AtForm>
                    </View>
                    <View className='b_mycompanyintro__footer'>
                        <AtButton className='item_btn' onClick={this.onSubmit.bind(this)}>保存</AtButton>
                    </View>
                </View>
            </View>
        )
    }
}
